

import { Withdrawals } from '../withdrawals/withdrawals-model.js';
import { My } from '../my/my-model.js';

import { Config } from '../config/config-model.js';
var withdrawals = new Withdrawals();

var my = new My();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false,
    accountIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that._loadData();
  },
  _loadData: function (options) {
    var that = this
    //页面加载完毕查询是否有银行卡信息
    withdrawals.selBankValue((data) => {
      var bkArr = new Array();
      for (var i in data) {
        bkArr.push(data[i]['bank_name'] + ' [尾号：' + data[i]['bank_number'].slice(-4) + ']')
      }
      console.log(bkArr)
      console.log(data)

      if (data.length == 0) {
        this.data.isBank = 0
      } else {
        this.data.isBank = 1

      }
      this.setData({
        isBank: this.data.isBank,
        accounts: bkArr
      })
    })
  },
  //select 选中
  bindAccountChange: function (e) {
    console.log('picker account 发生选择改变，携带值为', e.detail.value);

    this.setData({
      accountIndex: e.detail.value
    })
  },
  //挑战到bank添加页
  bankUrl: function () {
    wx.navigateTo({
      url: '../bank/bank'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var page = getCurrentPages().pop();
    if (page == undefined || page == null) return;
    page._loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})